package com.unifiedlibrary.amall_page.module.offerlist;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.base.common.basicUtils.DisplayUtils;
import com.unifiedlibrary.amall_page.R;

/**
 * 首页内容适配器
 */
public class OfferListAdapter extends RecyclerView.Adapter<OfferListAdapter.OfferListViewHolder> {

    private Context mContext;
    private final int widthScreen;
    private final int heightScreen;
    private int pxForSize;

    public OfferListAdapter(Context mContext) {
        this.mContext = mContext;

        int[] screenSize = DisplayUtils.getScreenSize(mContext);
        widthScreen = screenSize[0];
        heightScreen = screenSize[1];

        pxForSize = DisplayUtils.dip2px(mContext, 280);
    }

    @NonNull
    @Override
    public OfferListViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View containtView = LayoutInflater.from(mContext).inflate(R.layout.item_offer_info, null);
        OfferListViewHolder listViewHolder = new OfferListViewHolder(containtView);
        return listViewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull OfferListViewHolder holder, int position) {
        //注意：androidx的recyclerView，是需要单独设置宽高的，否则会出现显示最小item的情况
        ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(widthScreen, pxForSize);
        holder.itemView.setLayoutParams(layoutParams);
    }

    @Override
    public int getItemCount() {
        return 20;
    }

    //构建分类列表
    public static class OfferListViewHolder extends RecyclerView.ViewHolder{

        public OfferListViewHolder(@NonNull View itemView) {
            super(itemView);
        }

        //构建列表中的view
    }

}
